using Senparc.Weixin.BrowserUtility;
using System;
using System.Web.Mvc;
namespace Senparc.Weixin.MP.MvcExtension
{
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
	public class WeixinInternalRequestAttribute : ActionFilterAttribute
	{
		private string _message;
		private string _ignoreParameter;
		public string RedirectUrl
		{
			get;
			set;
		}
		public WeixinInternalRequestAttribute(string message, string ignoreParameter = null)
		{
			this._message = message;
			this._ignoreParameter = ignoreParameter;
		}
		public override void OnActionExecuting(ActionExecutingContext filterContext)
		{
			if (string.IsNullOrEmpty(this._ignoreParameter) || string.IsNullOrEmpty(filterContext.RequestContext.HttpContext.Request.QueryString[this._ignoreParameter]))
			{
				if (!BroswerUtility.SideInWeixinBroswer(filterContext.HttpContext))
				{
					ActionResult result;
					if (!string.IsNullOrEmpty(this.RedirectUrl))
					{
						result = new RedirectResult(this.RedirectUrl);
					}
					else
					{
						ContentResult contentResult = new ContentResult();
						contentResult.Content = this._message;
						result = contentResult;
					}
					filterContext.Result = result;
				}
			}
			base.OnActionExecuting(filterContext);
		}
	}
}
